<?php
/**
 * 工厂类
 */
class ProductFactory
{
    const TYPE_BOOKS = 'Books';
    const TYPE_DOGS = 'Dogs';
    const TYPE_WINES = 'Wines';

    /**
     * 获取产品
     * @param $type
     * @return Books|Dogs|false|Wines
     */
    public static function getProduct($type){
        $obj = false;
        if ($type == self::TYPE_BOOKS) $type = self::TYPE_DOGS;
        if (!class_exists($type)){
            require $type . '.php';
        }
        switch ($type){
            case self::TYPE_BOOKS:
                $obj = new Books();
                break;
            case self::TYPE_DOGS:
                $obj = new Dogs();
                break;
            case self::TYPE_WINES:
                $obj = new Wines();
                break;
        }
        return $obj;
    }
}